package com.sunducation.wts.room

import androidx.room.Room

//第二种创建db的方法
object DBInstance {
    //    private static final String DB_NAME = "/sdcard/LianSou/room_test.db";
    private val DB_NAME = "test.db"
    private var appDataBase: AppDatabase? = null
    fun getInstance(): AppDatabase? {
        if (appDataBase == null) {
            synchronized(DBInstance::class.java) {
                if (appDataBase == null) {
                    appDataBase = Room.databaseBuilder(
                        MyApplication.application,
                        AppDatabase::class.java,
                        DB_NAME
                    )
                        //不推荐打开这句，但是为了demo展示，我只能打开了
                        .allowMainThreadQueries()

                        .build()
                }
            }
        }
        return appDataBase
    }

}